Package aspect.example

Source Code of aspect.example.FollowEntity

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aspect.example;

import aspect.entity.Entity;
import aspect.entity.behavior.Behavior;
import aspect.physics.Motion;

/**
*
* @author vincent
*/
public class FollowEntity extends Behavior {

    private final Entity entity;
    private final float maxSpeed;

    public FollowEntity(Entity entity) {
        this.entity = entity;
        this.maxSpeed = entity.getBehavior(Motion.class).velocity.mag();
    }

    @Override
    public void update() {
        Motion m = ent.getBehavior(Motion.class);

        m.acceleration = entity.transform.position.minus(ent.transform.position).normalize().times(10.0f);

        if (m.velocity.mag() > maxSpeed) {
            m.velocity = m.velocity.normalize().times(maxSpeed);
        }

        ent.transform.setForward(m.velocity);
    }
}
TOP

Related Classes of aspect.example.FollowEntity

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.